package com.ccb.jyzx.expand.ouapi.controller;

import com.ccb.jyzx.expand.ouapi.beans.DepartmentInfo;
import com.ccb.jyzx.expand.ouapi.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ccb.jyzx.expand.ouapi.view.request.IdRequest;
import com.ccb.jyzx.expand.ouapi.view.request.OrgIdRequest;
import com.ccb.jyzx.expand.ouapi.view.respons.SimpleListResponseResult;
import com.ccb.jyzx.expand.ouapi.view.respons.TreeData;

import java.util.ArrayList;
import java.util.List;

/**
 * @author XIEFEI
 * @date 2019-11-12 14:15
 * @Description 部门信息接口
 **/
@Controller
@RequestMapping("/ooapi/api/dep")
@Api(tags = "部门信息相关接口")
public class DepartmentController {

    @Autowired
    DepartmentService departmentService;


    @ApiOperation(value = "根据id查询部门信息", notes = "根据id查询部门信息")
    @ResponseBody
    @PostMapping(value = "getById", consumes = "application/json;charset=UTF-8")
    public DepartmentInfo getReport(@RequestBody IdRequest json) {
        return StringUtils.isNotBlank(json.getId()) ? departmentService.getById(json.getId()) : new DepartmentInfo();
    }

    @ApiOperation(value = "查询所有部门信息", notes = "查询所有部门信息")
    @ResponseBody
    @PostMapping(value = "getAll", consumes = "application/json;charset=UTF-8")
    public List<DepartmentInfo> getAll() {
        return departmentService.getAll();
    }

    @ApiOperation(value = "根据组织ID查询部门信息", notes = "根据组织ID查询部门信息")
    @ResponseBody
    @PostMapping(value = "getByOrgId", consumes = "application/json;charset=UTF-8")
    public List<DepartmentInfo> getByOrgId(@RequestBody OrgIdRequest json) {
       return  StringUtils.isNotBlank(json.getOrgId())?departmentService.getByOrgId(json.getOrgId()):new ArrayList<>();
    }
    @ApiOperation(value = "查询所有部门信息", notes = "查询所有部门信息")
    @ResponseBody
    @PostMapping(value = "getAllDep", consumes = "application/json;charset=UTF-8")
    public List<DepartmentInfo>  getAllDep() {
        return departmentService.getAllDep();
    }

    @ApiOperation(value = "查询所有部门信息(Tree型结构)", notes = "查询所有部门信息")
    @ResponseBody
    @PostMapping(value = "getAllDepTree", consumes = "application/json;charset=UTF-8")
    public SimpleListResponseResult  getAllDepTree() {
        List<TreeData> data = new ArrayList<>();
        data.add(departmentService.getAllDepTree());
        return new SimpleListResponseResult<TreeData>(true,200,data,"请求成功");
    }

    @ApiOperation(value = "根据组织ID查询部门信息", notes = "根据组织ID查询部门信息")
    @ResponseBody
    @PostMapping(value = "getByOrgIdDep", consumes = "application/json;charset=UTF-8")
    public List<DepartmentInfo> getByOrgIdDep(@RequestBody OrgIdRequest json) {
        return  StringUtils.isNotBlank(json.getOrgId())?departmentService.getByOrgIdDep(json.getOrgId()):new ArrayList<>();
    }
}
